package org.simple.learning.spring.boot.mybatis.mapper;

import org.apache.ibatis.jdbc.SQL;
import org.simple.learning.spring.boot.mybatis.model.User;

/**
 * @author guihuo (E-mail:1620657419@qq.com)
 * @version v1.0 创建时间：2017/10/21 22:30
 * UserSqlProvider
 */
public class UserSqlProvider {

    public String insetSelective(User record) {
        SQL sql = new SQL();
        sql.INSERT_INTO("user");

        if (record.getId() != null) {
            sql.VALUES("id", "#{id,jdbcType=INTEGER}");
        }

        if (record.getUsername() != null) {
            sql.VALUES("username", "#{username,jdbcType=VARCHAR}");
        }

        return sql.toString();
    }

    public String updateByPrimaryKeySelective(User record) {
        SQL sql = new SQL();
        sql.UPDATE("user");

        if (record.getUsername() != null) {
            sql.SET("username = #{username,jdbcType=VARCHAR}");
        }

        sql.WHERE("id = #{id,jdbcType=INTEGER}");

        return sql.toString();
    }
}